from fastapi import Request, status
from fastapi.responses import JSONResponse
from app.utils.response_handler import ErrorResponse

async def not_found_handler(request: Request, exc: Exception):
    return JSONResponse(
        status_code=status.HTTP_404_NOT_FOUND,
        content=ErrorResponse(
            code=status.HTTP_404_NOT_FOUND,
            message="Resource not found"
        ).dict()
    )

async def internal_error_handler(request: Request, exc: Exception):
    return JSONResponse(
        status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
        content=ErrorResponse(
            code=status.HTTP_500_INTERNAL_SERVER_ERROR,
            message="Internal server error"
        ).dict()
    )

async def bad_gateway_handler(request: Request, exc: Exception):
    return JSONResponse(
        status_code=status.HTTP_502_BAD_GATEWAY,
        content=ErrorResponse(
            code=status.HTTP_502_BAD_GATEWAY,
            message="Bad gateway"
        ).dict()
    )

async def service_unavailable_handler(request: Request, exc: Exception):
    return JSONResponse(
        status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
        content=ErrorResponse(
            code=status.HTTP_503_SERVICE_UNAVAILABLE,
            message="Service temporarily unavailable"
        ).dict()
    )